var url = location.href, title = $(".title").text(), $chtml = $(".post-single-content"), content = $chtml.find("p").text(), pics = "", desc = "";

/**
 * 分享多图暂只有QQ空间支持
 */
if ($chtml.find("img").length >= 1) {
    for (var i = 0; i < $chtml.find("img").length; i++) {
        pics += $chtml.find("img")[i].src + "|";
    }
    if (pics.length - 1 == pics.lastIndexOf("|")) {
        pics = pics.slice(0, pics.length - 1);
    }
}

desc = "【" + title + "】" + content.replace(/(^\s*)|(\s*$)/g, "");

if (desc.length > 120) {
    desc = desc.substr(0, 117) + "...";
}

var qq = {
    url:url,
    site:"Dreamlu开源博客",
    title:title,
    pics:pics,
    desc:desc
};

var sina = {
    url:url,
    pic:pics.split("|")[0],
    title:desc,
    rnd:new Date().valueOf()
};

var renren = {
    resourceUrl:url,
    srcUrl:url,
    pic:pics.split("|")[0],
    title:title,
    description:desc
};

var qqmb = {
    url:url,
    pic:pics.split("|")[0],
    title:desc,
    assname:"Dreamlu开源博客"
};

var neteasemb = {
    source:"Dreamlu开源博客",
    images:pics.split("|")[0],
    info:desc
};

$(function() {
    $(".lcm_share a").click(function() {
        var way = $(this).data("share");
        if (way === "qq") {
            var temp = [];
            for (var i in qq) {
                temp.push(i + "=" + encodeURI(qq[i] || ""));
            }
            $(this).attr("href", "http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?" + temp.join("&"));
        } else if (way === "sina") {
            var temp = [];
            for (var i in sina) {
                temp.push(i + "=" + encodeURI(sina[i] || ""));
            }
            $(this).attr("href", "http://service.weibo.com/share/share.php?" + temp.join("&"));
        } else if (way === "qqmb") {
            var temp = [];
            for (var i in qqmb) {
                temp.push(i + "=" + encodeURI(qqmb[i] || ""));
            }
            $(this).attr("href", "http://share.v.t.qq.com/index.php?c=share&a=index&" + temp.join("&"));
        } else if (way === "renren") {
            var temp = [];
            for (var i in renren) {
                temp.push(i + "=" + encodeURI(renren[i] || ""));
            }
            $(this).attr("href", "http://widget.renren.com/dialog/share?" + temp.join("&"));
        } else if (way === "neteasemb") {
            var temp = [];
            for (var i in neteasemb) {
                temp.push(i + "=" + encodeURI(neteasemb[i] || ""));
            }
            $(this).attr("href", "http://t.163.com/article/user/checkLogin.do?" + temp.join("&"));
        }
    });
});